// EditUserInfoActivity.java
package com.example.finalhomework_lienyu;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class EditUserInfoActivity extends AppCompatActivity {
    private EditText editTextUserName;
    private EditText editTextUserAccount;
    private Button buttonSave;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_user_info);

        editTextUserName = findViewById(R.id.editText_user_name);
        editTextUserAccount = findViewById(R.id.editText_user_account);
        buttonSave = findViewById(R.id.button_save);

        // Load current user info
        Intent intent = getIntent();
        editTextUserName.setText(intent.getStringExtra("user_name"));
        editTextUserAccount.setText(intent.getStringExtra("user_account"));

        buttonSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String userName = editTextUserName.getText().toString().trim();
                String userAccount = editTextUserAccount.getText().toString().trim();

                if (TextUtils.isEmpty(userName) || TextUtils.isEmpty(userAccount)) {
                    Toast.makeText(EditUserInfoActivity.this, "用户名或账号不能为空", Toast.LENGTH_SHORT).show();
                } else {
                    Intent resultIntent = new Intent();
                    resultIntent.putExtra("user_name", userName);
                    resultIntent.putExtra("user_account", userAccount);
                    setResult(Activity.RESULT_OK, resultIntent);
                    finish();
                }
            }
        });
    }
}
